package com.ecable.action;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.exception.ConnectionException;
import com.ecable.exception.DataNotFoundException;
import com.ecable.bean.VillageTO;

import com.ecable.util.UtilConstants;
import com.ecable.delegate.VillageMgrDelegate;
public class ViewVillageOperatorsAction extends HttpServlet {


	/**
	 * 
	 */
	private static final long serialVersionUID = -5793309292004834617L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String usertype=request.getParameter("usertype");
		
		RequestDispatcher rd=null;

		Vector<VillageTO> vsto=null;
		String path="";
		String sname="";
		String dname="";
		
		try{
			VillageMgrDelegate vmd=new VillageMgrDelegate();
			try{
				
				sname=request.getParameter("sname");
				System.out.println("in action sname============"+sname);
				 dname=request.getParameter("dname");
			
				 System.out.println("in action dname============"+dname);
			 vsto=vmd.getVillageName(dname);
			}
			catch (ConnectionException ce) {
				throw new ServletException("server busy please try again");
			}
			
			catch (DataNotFoundException le) {
				request.setAttribute("status", UtilConstants._ALL_OPERATOR_FAILED);
				rd=request.getRequestDispatcher(UtilConstants._LOGIN_FAILED_PAGE);
			}
			
			
			
			if(vsto!=null){
				
				request.setAttribute("villages", vsto);
				request.setAttribute("usertype", usertype);
				request.setAttribute("statename", sname);
				request.setAttribute("districtname", dname);
				request.setAttribute("status", UtilConstants._ALL_OPERATORS);
				System.out.println(vsto);
				path=UtilConstants._VIEW_OPERATORS;
				
				}
			else{
				
				request.setAttribute("status", UtilConstants._ALL_OPERATOR_FAILED);
				request.setAttribute("usertype", usertype);
				path=UtilConstants._VIEW_OPERATORS;
				
			}
		}
		catch (ServletException e) {
			
			e.printStackTrace();
			
		}
		
		rd=request.getRequestDispatcher(path);
		rd.forward(request, response);
		
		
	}
		
		
		
	}


